//
//  MXSButton.swift
//  sweepMine
//
//  Created by 孙飞 on 15/12/27.
//  Copyright © 2015年 Sunfei. All rights reserved.
//

import UIKit

class MXSButton: UIButton {
    
    
    var mine: mineModel?
    {
        didSet{
            
            setDataForItem()
        }
    }
    
    var mineLabel:UILabel = {
        
        var mineLabel = UILabel()
        mineLabel.textAlignment = .Center
        mineLabel.textColor = UIColor.darkGrayColor()
        //        mineLabel.text = mine.numb
        return mineLabel
    }()
    var isLabel:UILabel = {
        
        var isLabel = UILabel()
        isLabel.textAlignment = .Center
        isLabel.textColor = UIColor.redColor()
        //        isLabel.text = mine.isMine
        return isLabel
    }()
    var aroundCount:UILabel = {
        
        var aroundCount = UILabel()
        aroundCount.textAlignment = .Center
        aroundCount.textColor = UIColor.darkGrayColor()
        //        isLabel.text = mine.isMine
        return aroundCount
    }()
    
    var mineBG: UIView = {
        var mineBG = UIView()
        return mineBG
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
//        mineBG!.layer.contents = UIImage(named: "mineIcon")?.CGImage
        backgroundColor = UIColor(red: 19 / 255.0, green: 19 / 255.0, blue: 19 / 155.0, alpha: 1)
        addSubview(mineLabel)
        addSubview(isLabel)
        addSubview(aroundCount)
        addSubview(mineBG)
        
        mineLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self)
            make.leading.equalTo(self)
            make.width.equalTo(self)
        }
        isLabel.snp_makeConstraints { (make) -> Void in
            //            make.top.equalTo(self).offset(13)
            //            make.leading.equalTo(self)
            make.center.equalTo(self)
            make.width.equalTo(self)
        }
        aroundCount.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(self)
            make.leading.equalTo(self)
            make.width.equalTo(self)
        }
        
        mineBG.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.leading.equalTo(self.snp_leading)
            make.width.equalTo(self)
            make.height.equalTo(self)
        }
        
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setDataForItem(){
        
//        mineLabel.text = String(mine!.numb)
//        aroundCount.text = String(mine!.aroundCount)
        
        isLabel.text = String(mine!.aroundCount)
        isLabel.font = UIFont.systemFontOfSize(20)
        isLabel.textColor = UIColor.redColor()
        if mine!.mineIcon == "safe"{
            
            isLabel.textColor = UIColor.greenColor()
        }
        isLabel.hidden = mine!.isHiddenCount!
        mineBG.hidden = mine!.isHiddenMine!
        if mine!.isMine == true {
            mineBG.layer.contents = UIImage(named: "mineIcon")?.CGImage
        }else {
           isLabel.hidden = mine!.isHiddenCount!
        }
    }
    
    


}
